using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MacomberMap.Common.Database_Interface.CIM.Components;
using MacomberMap.Common.Internals;

namespace MacomberMap.Common.Database_Interface.CIM.One_Line_Interface
{
    /// <summary>
    /// This class displays a dialog box
    /// </summary>
    public partial class frmSubstationChooser : Form
    {
        #region Variable declarations
        /// <summary>
        /// The selected CIM element
        /// </summary>
        public CIM_Element SelectedElement
        {
            get { return (cmbSubstation.SelectedItem as DataRowView)[1] as CIM_Element; }
            set { cmbSubstation.SelectedItem = value; }
        }

        /// <summary>The collection of substations</summary>
        private static DataTable Subs = null;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new substation chooser
        /// </summary>
        public frmSubstationChooser()
        {
            InitializeComponent();

            if (Subs == null)
            {
                Subs = new DataTable("Substations");
                Subs.Columns.Add("Name", typeof(String));
                Subs.Columns.Add("Substation", typeof(CIM_Element));
            }

            if (Subs.Rows.Count == 0)
                foreach (CIM_Element Substation in MM_Database_CIM.ElementsOfType("cim:Substation"))
                    Subs.Rows.Add(MM_Repository.TitleCase(Substation.Name) + " (" + MM_Repository.TitleCase(Substation["cim:IdentifiedObject.description"]) + ")", Substation);


            DataView dV = new DataView(Subs);
            dV.Sort = "Name";

            cmbSubstation.DataSource = dV;
            cmbSubstation.DisplayMember = "Name";
            cmbSubstation.ValueMember = "Substation";
            
        }
        #endregion

    }
}